package dog.gui.calendar;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JPanel;

import containers.AppKey;

import dog.gui.GUI;
import dog.gui.MenuBarPanel;
import dog.gui.NewsPanel;
import dog.gui.PersonList;
import dog.model.Model;

@SuppressWarnings("serial")
public class CalendarPanel extends JPanel
	{
	private AppKey hover;
	private AppKey select;
	private Day[] days;
	private Model model;
	
	public CalendarPanel(GUI gui, Model model,NewsPanel newsPanel)
		{
		this.setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		this.model = model;
		days = new Day[7];
		c.gridx=0;
		c.gridy=0;
		c.gridwidth=7;
		add(new MenuBarPanel(model),c);
		
		
		c.gridx=8;
		c.gridy=1;
		c.gridheight=1;
		add(newsPanel,c);
		
		
		c.gridwidth=1;
		c.gridx=8;
		c.gridy=0;
		PersonList personList = new PersonList(model,this);
		add(personList,c);
		
		c.gridwidth=1;
		c.gridy=1;
		c.gridx=0;
		add(new DayTimes(model),c);
		for(int i=0; i<7; i++)
			{
			c.gridx=i+1;
			days[i]=new Day(this,gui,model,i+1);
			add(days[i],c);
			}
		}
	public void setHover(AppKey hover)
		{
		this.hover=hover;
		repaint();
		}
	public AppKey getHover()
		{
		return hover;
		}
	public void setSelect(AppKey select)
		{
		model.setSelected(select);
		this.select=select;
		repaint();
		}
	public AppKey getSelect()
		{
		return select;
		}
	public int getStatus(AppKey key)
		{
		if (select!=null)
    		{
    		if (select.equals(key))
    			return 2;
    		}
		if(hover!=null)
			{
			if (hover.equals(key))
				return 1;
			}
    	return -1;
		}
	public void SelectionChanged(int pID)
		{
		//person selection changed;
		model.gui_setAccessPerson(pID);
		}
	public void IsInSelection(int personID, boolean b)
		{
		if (b)
			{
			if (!model.isAccessingPerson(personID))
				model.gui_accessPerson(personID);
			}
		else
			{
			if (model.isAccessingPerson(personID))
				{System.out.println("Remove call from CalendarPanel");
				model.gui_unsetPerson(personID);}
			}
		}
	}
